package main

import (
	"fmt"
	"reflect"
)

func main() {
	var c Cal = Cal{
		Num01: 55.1,
		Num02: 22.2,
	}
	typeOf := reflect.TypeOf(c)
	valueOf := reflect.ValueOf(c)

	fmt.Println("打印所有的字段：")
	numField := typeOf.NumField()
	for i := 0; i < numField; i++ {
		fieldName := typeOf.Field(i).Name
		fmt.Println(fieldName)
	}

	fmt.Println("调用方法：", typeOf.Method(0).Name, "运行结果：")
	var params01 []reflect.Value = make([]reflect.Value, 0)
	params01 = append(params01, reflect.ValueOf("tom"))
	valueOf.Method(0).Call(params01)

}

type Cal struct {
	Num01 float64 `json:"num-01"`
	Num02 float64 `json:"num-02"`
}

// GetSub
//
//	@Description:
//	@receiver c
//	@param name
func (c Cal) GetSub(name string) {
	var res = c.Num01 - c.Num02
	var str = fmt.Sprintf("%s完成了减法运行， %f-%f=%f", name, c.Num01, c.Num02, res)
	fmt.Println(str)

}
